<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>
<body>
<div id="toolbar" class="toolbar" style="margin-left: 5px;">
    <a class="add-btn btn btn-sm btn-success"><i class="fa fa-plus" aria-hidden="true"></i> 新增</a>
</div>



<!-- START 数据表格 -->
<table id="coefficientTable"
       data-toolbar="#toolbar"
       data-pagination="true"
       data-resizable="true"
       data-side-pagination="server"
       data-url="/sea/physical/coefficient/findByCnd.do"
       data-page-size="15"
       class="table table-striped table-hover"
>
</table>


<div id="layer_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-form" method="post" autocomplete="off" style="margin: auto">
            <div class="form-group" style="margin-top: 20px">
                <label class="category control-label col-sm-2" style="max-width: 100px">国家</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <select name="coefficientCode"  class=" coefficientCode form-control " >
                        <option value="">请选择国家</option>
                        <%for(var dict in country){%>
                        <option value="${dict.detailCode}">${dict.detailName}</option>
                        <%}%>
                    </select>
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="category control-label col-sm-2" style="max-width: 100px">系数</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" name="coefficientCoef" class="coefficientCoef form-control" onkeyup="value=value.replace(/[^\d?.{1}\d{2}]/g,'')">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>



<div id="layer_edit_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-edit-form" method="post" autocomplete="off" style="margin: auto">
            <input type="hidden" id="id" name="id">
            <div class="form-group" style="margin-top: 20px">
                <label class="category control-label col-sm-2" style="max-width: 100px">国家</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <select name="coefficientCode" id="coefficientCode" class="form-control" >
                        <option value="">请选择国家</option>
                        <%for(var dict in country){%>
                        <option value="${dict.detailCode}">${dict.detailName}</option>
                        <%}%>
                    </select>
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="category control-label col-sm-2" style="max-width: 100px">系数</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="coefficientCoef" name="coefficientCoef" class="form-control" onkeyup="value=value.replace(/[^\d?.{1}\d{2}]/g,'')">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="edit-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>



<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer'}){}%>
<script>
    var $coefficientTable = $('#coefficientTable');

    $(function () {

        // START 表格配置
        $coefficientTable.bootstrapTable({
            pageSize:10,
            columns: [
                {
                    title: '国家',
                    field: 'coefficientName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title : '系数',
                    field: 'coefficientCoef',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '操作',
                    field: 'operate',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){
                // 删除
                $('.del-coefficient-btn').on('click',function () {
                    var id = $(this).attr('data-val');
                    layer.confirm('确定删除？', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        $.post('/sea/physical/coefficient/delete.do',{id: id},function(data){
                            if( data.ok ){
                                $("#coefficientTable").bootstrapTable('refresh');
                                layer.msg(data.msg,{icon: 1,time: 1500});
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 1500});
                            }
                        });
                    });
                });

                // 修改
                $('.edit-coefficient-btn').on('click',function () {
                    var id = $(this).attr('data-val');
                    $("#id").val(id);
                    var coef = $(this).attr('data-val-coef');
                    $("#coefficientCoef").val(coef);
                    var code = $(this).attr('data-val-code');
                    $("#coefficientCode").val(code);
                    layer.open({
                        type:1,
                        title:'修改申报系数',
                        area:['600px','300px'],
                        skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                        shadeClose:false,
                        resize: false,
                        scrollbar: false,
                        maxmin: false,//出现最大化按钮
                        content:$('#layer_edit_window')
                    })
                });
            }
        });

        // 条件查询
        $('.search-btn').on('click',function () {
            $coefficientTable.bootstrapTable('refresh', { url:'${ctxPath}/bbpk/physical/coefficient/findByCnd.do?'+$('#search-form').serialize() });
        });

        // 添加
        $('.add-btn').on('click',function () {
            layer.open({
                type:1,
                title:'新增申报系数',
                area:['600px','300px'],
                skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                shadeClose:false,
                resize: false,
                scrollbar: false,
                maxmin: false,//出现最大化按钮
                content:$('#layer_window')
            })
        });
    });


    //提交表单
    $('.save-btn').on('click',function(){
        layer.confirm('确定要新增当前数据？', {
            btn: ['确定','取消'],title:'提示'
        }, function(){
            var coefficientCode=$(".coefficientCode").val();
            if(coefficientCode==''){
                parent.layer.msg('请选择国家！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var coefficientCoef=$(".coefficientCoef").val();
            if(coefficientCoef==''){
                parent.layer.msg('请填写系数！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            alert(coefficientCode);
            layer.closeAll();
            var index=layer.load();
            $.post('/sea/physical/coefficient/save.do',{coefficientCoef:coefficientCoef,coefficientCode:coefficientCode},function(data){
                if( data.ok ){
                    $coefficientTable.bootstrapTable('refresh');
                    layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }else{
                    layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            });
        });
    });


    //提交表单
    $('.edit-btn').on('click',function(){
        layer.confirm('确定要新增当前数据？', {
            btn: ['确定','取消'],title:'提示'
        }, function(){
            var coefficientCode=$("#coefficientCode").val();
            if(coefficientCode==''){
                parent.layer.msg('请选择国家！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var coefficientCoef=$("#coefficientCoef").val();
            if(coefficientCoef==''){
                parent.layer.msg('请填写系数！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            layer.closeAll();
            var index=layer.load();
            $.post('/sea/physical/coefficient/usave.do',{id:$("#id").val(),coefficientCoef:coefficientCoef,coefficientCode:coefficientCode},function(data){
                if( data.ok ){
                    $coefficientTable.bootstrapTable('refresh');
                    layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }else{
                    layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            });
        });
    });


    // 操作菜单
    function optFormatter(value,row){
        var content = '<button class="edit-coefficient-btn btn btn-xs btn-info" data-val="'+row.id+'" data-val-coef="'+row.coefficientCoef+'" data-val-code="'+row.coefficientCode+'" title="修改"><i class="fa fa-edit"></i>  </button>';
        content += '<button class="del-coefficient-btn btn btn-xs btn-danger" data-val="'+row.id+'" title="删除"><i class="fa fa-trash-o"></i>  </button>';
        return content;
    }
</script>
</body>
</html>